package com.small.web;

import java.util.HashMap;
import java.util.Map;

/**
 * 请求参数对象
 * Created by fangzheng on 2018/1/30.
 */
public class Param {
    private Map<String, Object> paramMap;

    public Param() {
        this.paramMap = new HashMap<String, Object>();
    }

    public Param(Map<String, Object> paramMap) {
        this.paramMap = new HashMap<String, Object>();
        this.paramMap = paramMap;
    }

    /**
     * 添加一个参数
     *
     * @param name
     * @param value
     */
    public void addParam(String name, Object value) {
        this.paramMap.put(name, value);
    }

    /**
     * 添加多个参数
     *
     * @param params
     */
    public void addParams(Map<String, Object> params) {
        this.paramMap.putAll(params);
    }

    /**
     * 获取所有参数map对象
     *
     * @return
     */
    public Map<String, Object> getParamMap() {
        return paramMap;
    }

    /**
     * 返回long型参数
     *
     * @param paramName
     * @return
     */
    public long getLong(String paramName) {
        if (null == paramName || "".equals(paramName)) return 0;
        Object object = paramMap.get(paramName);
        return Long.valueOf(String.valueOf(object)).longValue();
    }

    /**
     * 返回字符串类型参数
     *
     * @param key
     * @return
     */
    public String getString(String key) {
        return paramMap.get(key).toString();
    }

    /**
     * 返回Integer类型参数
     *
     * @param key
     * @return
     */
    public Integer getInteger(String key) {
        return (Integer) paramMap.get(key);
    }

    /**
     * 返回参数
     *
     * @param key
     * @return
     */
    public Object get(String key) {
        return paramMap.get(key);
    }


}
